<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>
<script>
import BScroll from 'better-scroll';

export default {
  name: "Scroll",
  data() {
    return {
      scroll: null,
    }
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    // 1. 创建BScroll对象
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: 3,
      pullUpLoad: true,
    });

    // 2. 监听滚动事件
    this.scroll.on('scroll', (position) => {
      //console.log(position);
      this.$emit('scroll', position);
    });

    // 3. 监听上拉事件
    this.scroll.on('pullingUp', () => {
      console.log('hhh');
    })
  },
  methods: {
    scrollTo(x, y, time=300) {
      this.scroll.scrollTo(x, y, time);
    },
  },
};
</script>
<style scoped>
</style>